package eco2automotive.tasks;
import eco2automotive.gui.Layout_KMHRPM;
import eco2automotive.port.ConnectionControl;
/**  
 *  Thread KMH/RPM
  * @version 1.0
  * @autor Fco. Javier Sánchez Esparza
  *
  */ 
public class Thread_KMHRPM extends Thread{
    ConnectionControl connControl;
    Layout_KMHRPM LAYOUT;
    private boolean next = true;    
   /**
     * Start the thread and @param connControl send the data 
     * @param connControl connection active object
     * @param LAYOUT JDialog used to display the monitor     
     */ 
public Thread_KMHRPM(ConnectionControl connControl, Layout_KMHRPM LAYOUT)
    {       
        this.connControl=connControl; 
        this.LAYOUT=LAYOUT;
    }
/**
 * Stop
 */
public void stop_Thread(){next=false;}
     
public void run()
   {
      while (next)
      {          
        if (connControl.DATA_AVAILABLE()==false)
        {
            connControl.TXData("010D");
            connControl.TXData("010C");            
            try{Thread.sleep(3000);}catch(Exception e){}            
            //Wait for a response
        }
        else{
        String data;                          
        //data = new String(connControl.getData());
        //data=new UtilString().ClearTotalData(data);                   
        for(int i=0;i<=connControl.getFata().getLength();i++){
            System.out.println("MANDO AL LAYOUT >>> "+i);            
              this.LAYOUT.updateData(connControl.getFata().extract().toString());
        }
        this.connControl.downFlag();
        }
   
      }
      
   } 
   
}
